/**   
*    
* @file
* @brief
*
* @<b>文件名</b>      : ReplyInfoList
* @n@n<b>版权所有</b>: 网龙应用软件开发一部
* @n@n<b>作  者</b>  : Administrator
* @n@n<b>创建时间</b>: 2014-2-7 下午5:52:02 
* @n@n<b>文件描述</b>:  
* @version  
*/
package com.common.weibolib;

import java.util.ArrayList;

import com.common.android.utils.parser.BaseType;

/**
 * ClassName:ReplyInfoList
 * Function: TODO ADD FUNCTION
 * Reason:	 TODO ADD REASON
 * 
 * @author   Administrator		
 * @version  
 * @since    Ver 1.1
 * @Date	 2014	2014-2-7		下午5:52:02
 *
 * @see 	 
 */

public class ReplyInfoList extends ArrayList<ReplyInfo> implements BaseType {

	public static final long serialVersionUID = 1L;

	public long TweetID;

	public int mTotal;
	/**
	 * 新消息的总数
	 */
	public int mNewCount;

	public void setTweetID(long tweetID) {
		TweetID = tweetID;
	}

	/**
	 * 获取某个时间戳的评论ID
	 * 
	 * @param timestamp
	 * @return
	 */
	public long getTweetIDByTimestamp(long timestamp) {
		for (ReplyInfo ri : this) {
			if (ri.post_time <= timestamp) {
				return ri.rid;
			}
		}
		return 0;
	}

	/**
	 * 获取Comment对应的Index
	 * 
	 * @param commentID
	 * @return
	 */
	public int indexOfTweet(long commentID) {
		for (ReplyInfo ri : this) {
			if (ri.rid == commentID) {
				return this.indexOf(ri);
			}
		}
		return 0;
	}

	/**
	 * 获取子列表
	 * 
	 * @return
	 */
	public ReplyInfoList subList(int start, int end) {
		if (end > this.size()) {
			end = this.size();
		}
		ReplyInfoList result = new ReplyInfoList();
		result.addAll(super.subList(start, end));
		return result;
	}

	/**
	 * 比列表位置都小
	 */
	public final static int ADDPOS_LESS = -1;

	/**
	 * 比列表位置都大
	 */
	public final static int ADDPOS_GREATER = -5;

	/**
	 * 重复数据
	 */
	public final static int ADDPOS_CONTAINS = -9;

	/**
	 * 获取新对象的插入位置
	 * 
	 * @return
	 */
	public int getAddPosOfItem(ReplyInfo reply) {
		int size = this.size();
		if (size == 0) {
			return 0;
		}
		long timestamp_add = reply.post_time;

		// 比列表的时间都新
		if (timestamp_add > this.get(0).post_time) {
			return ADDPOS_LESS;
		}
		// 比列表的时间都旧
		if (timestamp_add < this.get(this.size() - 1).post_time) {
			return ADDPOS_GREATER;
		}

		for (int i = 0; i < size; i++) {
			ReplyInfo ri = this.get(i);
			if (timestamp_add > ri.post_time) {
				return i;
			}
		}

		return ADDPOS_GREATER;
	}

	/**
	 * @n<b>函数名称</b> :deleteById
	 * @brief
	 * @see
	 * @param @param sinaID 发送企业微博时同步到sina微博的id
	 * @param @param sameCommentInNd 原企业微博
	 * @return void
	 * @<b>作者</b> : cb
	 * @<b>创建时间</b> : 2013-3-22上午11:16:11
	 */
	public void deleteById(long sinaID, ReplyInfo orcCommentInNd) {
		for (ReplyInfo ri : this) {
			if (ri.rid == sinaID) {
				this.remove(ri);
				return;
			}
		}
	}

	public void setNewCount(int num) {
		mNewCount = num;
	}

	public int getNewCount() {
		return mNewCount;
	}
}

